<button class="btn btn-success btn-sm" data-toggle="modal" data-target="#exampleModal2">新增一级分类</button>

<div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModal2"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="font-size: 36px;">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">新增一级分类</h4>
            </div>
            <div class="modal-body">
                <div class="mb-3">
                    <label for="exampleFormControlInput1" class="form-label">分类名</label>
                    <input type="text" name="categoryName" class="form-control" id="exampleFormControlInput1"
                           placeholder="请输入一级分类名">
                </div>
                <div class="mb-3">
                    <label for="exampleFormControlInput1" class="form-label">状态</label>
                    <select class="form-select form-control" name="categoryStatus">
                        <option selected value>请选择状态</option>
                        <option value="1">打开</option>
                        <option value="2">关闭</option>
                    </select>
                </div>
                <div class="mb-3">
                    <label for="exampleFormControlInput1" class="form-label">排序</label>
                    <input type="number" class="form-control" name="sort" placeholder="请输入排序值">
                </div>
                <div class="mb-3">
                    <label for="exampleFormControlInput1" class="form-label">分类图片路径：</label>
                    <input type="text" class="form-control" name="classImgUrl" placeholder="请输入分类图片路径值">
                </div>
                <div class="mb-3">
                    <label for="exampleFormControlInput1"
                           class="form-label">分类跳转地址（如外链请使用http或https开头）：</label>
                    <input type="text" class="form-control" name="classJumpUrl" placeholder="请输入分类跳转地址">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" onclick="addCategory()">提交</button>
            </div>
        </div>
    </div>
</div>
<script src="/js/utils/ajaxFunc.js"></script>
<script>
    function addCategory() {
        ajaxPostFunc('/admin/ajax/addCategory', {
            category_name: $("input[name='categoryName']").val(),
            category_status: $("select[name='categoryStatus']").val(),
            category_sort: $("input[name='sort']").val(),
            category_img: $("input[name='classImgUrl']").val(),
            category_jump: $("input[name='classJumpUrl']").val(),
            _token: $.admin.token
        }, {}, res => {
            console.log(res);
            window.location.reload();
        });
    }
</script>
